<template>
	<uPopup v-model="show2" mode="center" border-radius="20">
			<view class="box p30">
				<view class="bcontent f34 c3 ">
					开启微信消息通知，{{text}}
				</view>
				<view class="btns t-flex between">
					<view class="bbtn cancle" @click="show2 = false">
						暂不需要
					</view>
					<view class="bbtn" @tap="msg">
						去开启
					</view>
				</view>
				
				<view class="none t-flex">
					<view class="" style="border-bottom: 1rpx solid #999;" @click="noPop">
						不再弹出授权提示
					</view>
				</view>
			</view>
	</uPopup>
	<u-toast ref="uToastE"></u-toast>
</template>

<script setup lang="ts">
import uPopup from "../../uni_modules/vk-uview-ui/components/u-popup/u-popup.vue"
import { ref } from "vue";
	
	const uToastE = ref()
	let count = ref(0)
	let text = ref('文本信息')
	const msg = ()=>{
		show2.value = false
		if(count.value == 0){
			wx.requestSubscribeMessage({
				tmplIds:msgType.value,
				success:(res)=>{
					console.log(res,msgType.value,'success')
					show2.value = false
				},
				fail:(res)=>{
					console.log('faile')
					console.log(res,msgType.value)
					show2.value = false
					count.value++
				}
			})
		}else{
			wx.openSetting({
				withSubscriptions:true,
				success(e){
					console.log(e,'settint')
				},
				fail(e) {
					console.log(e,'fail')
				}
			})
		}
		

	}
	const show2 = ref(false)
	const msgType = ref([])
	
	const noPop = ()=>{
		uni.setStorage({
			key:'noPop_type1',
			data:1
		})
		uToastE.value.show({
			title:'已取消授权提示，若后续需要开启消息提示请打开右上角设置',
			type:'success',
			position:'top',
			duration:'4000'
		})
		show2.value = false
	}
	
	defineExpose({
		show2,
		count,
		msgType,
		text
	})
</script>

<style scoped lang="scss">
	.box{
		width: 600rpx;
		box-sizing: border-box;
		overflow: hidden;
	}
	.btitle{
		background-color:#eee;
		color: #333;
		text-align: center;
		padding: 20rpx 0 ;
		margin-bottom: 20rpx;
	}
	.btns{
		margin-top: 60rpx;
	}
	.bbtn{
		width: 260rpx;
		background-color: $main-color;
		color: #fff;
		margin: 20rpx auto;
		padding: 20rpx 0;
		text-align: center;
		border-radius: 10rpx;
		margin-top: 50rpx;
	}
	.bbtn.cancle{
		background-color: #fff;
		border: 1px solid #CECECE;
		color: #666;
	}
	
	.bcontent{
		font-weight: 600;
		text-align: center;
	}
	.none{
		padding: 20rpx;
		font-size: 24rpx;
		color: #999;
		justify-content: flex-end;
	}
</style>